﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChinessChess
{
    class CTot:CQuanCo
    {
        private int new_Index, old_Index;
        
        public CTot() { 
        }
        public CTot(COCo[] chess, int newIndex, int oldIndex, ChessColor color)
            : base(chess, color)
        {
            this.new_Index = newIndex;
            this.old_Index = oldIndex;
        }
        

        public override bool CheckIndex(){
            if (!isOver()){
                switch (Color) {
                    case ChessColor.white: {
                        if (new_Index - old_Index == 9) {
                            return true;
                        }
                        break;
                    }
                    case ChessColor.black:{
                        if (old_Index - new_Index == 9){
                            return true;
                        }
                            break;
                        }
                }
            }
            else {
                if (Math.Abs(new_Index - old_Index) == 9 || Math.Abs(new_Index - old_Index) == 1) {
                    return true;
                }
            }
            return false;
        }
        public override bool CheckPoint(){
            int dong = flag[new_Index].Dong - flag[old_Index].Dong;
            int cot = flag[new_Index].Cot - flag[old_Index].Cot;
            if (!isOver()){
                if (Math.Abs(dong) == 1 && CheckIndex()) {
                    return true;
                }
            }
            else {
                if ((Math.Abs(dong) == 1 || Math.Abs(cot)==1) && CheckIndex()){
                    return true;
                }
            }
            return false;
        }

        //Kiem tra tot da sang song chua
        private Boolean isOver() {
            switch (Color) {
                case ChessColor.white: {
                    if (flag[old_Index].Dong > 4) {
                        return true;
                    }
                    break;
                }
                case ChessColor.black : {
                    if (flag[old_Index].Dong < 5)
                    {
                        return true;
                    }
                        break;
                    }
            }
            return false;
        }
    }
}
